
#python调用bat文件 执行cmd命令,没有打开cmd黑窗口的
#https://www.cnblogs.com/lrw3716740/p/5158494.html


import os
import sys
import struct
import subprocess
from sys import executable
from subprocess import Popen, CREATE_NEW_CONSOLE

#D:/zhh/learns/py3Utils/callByPy.bat

batPath = 'D:/zhh/learns/py3Utils/callByPy.bat'
#无法获取返回值
statu = os.system(batPath)
print("statu",statu) #只返回一个状态

#可以获取返回值
p = os.popen(batPath)
print('得到的返回值:',p.read())

#通过子进程执行 http://blog.csdn.net/u010649766/article/details/75573887
# https://www.cnblogs.com/zhoug2020/p/5079407.html   subprocess.Popen 函数参数详解
clientPath="E:/H5Game/Client"
svnLog = 'svn log {0} -l 5'.format(clientPath)
sub = subprocess.Popen(svnLog,
shell=True,
stdout=subprocess.PIPE,stderr=subprocess.STDOUT,encoding="GB2312") #stdout=subprocess.PIPE 设置标准输出流的目标 subprocess.PIPE 表示创建新的管道 encoding="GB2312"
sub.wait()
retStr = sub.stdout.read()
#print("retStr",retStr.split("\n"))

import re

def get_svn_log_Inf(retStr,last_version):
    logArr = retStr.split("\n")    
    retArr = []
    cnt = len(logArr)
    curStr = ""
    for i in range(cnt):
        tempStr = logArr[i]    
        idx = tempStr.find('----------------------------')    
        #print("tempStr",tempStr,"i",i)    
        if idx==-1:
            if tempStr=="":
                curStr+="|"
            else:            
                curStr+=tempStr
        else:
            if curStr!="":
                retArr.append(curStr)
                ver = get_log_version(curStr)+1
                #print("ver",ver,"last_version",last_version)
                if str(ver)==str(last_version):
                    break
            curStr = ""
    if cnt>0:
        curStr = retArr[0]    
    print("retArr[0]",retArr[0])
    return curStr
    
def get_log_version(curStr):
    arr = curStr.split("|")
    mObj = re.search(r"\d+",arr[0])
    ver = 0
    if mObj:
        ver = int(mObj.group())
    return ver

get_svn_log_Inf(retStr,7568)
#print("子进程得到的结果:",ret)


